package tuanda.soict.firstsun.LogicPackage;

/**
 * @author tuanda_soict_hut
 * @version 0.0.1
 * @since 1-8-2012
 */
public class Coordinate {

	private int locationX;
	private int locationY;

	public Coordinate(int x, int y) {
		setLocation(x, y);
	}

	public Coordinate() {
		setLocation(0, 0);
	}

	public Coordinate(Coordinate coor) {
		if (coor != null) {
			setLocation(coor.getLocationX(), coor.getLocationY());
		} else {
			setLocation(0, 0);
		}
	}

	public final int getLocationX() {
		return this.locationX;
	}

	public final int getLocationY() {
		return this.locationY;
	}

	public final Coordinate getCoordinate() {
		return this;
	}

	public final void setLocation(int x, int y) {
		if (x > -1 && y > -1) {
			this.locationX = x;
			this.locationY = y;
		} else {
			this.locationX = 0;
			this.locationY = 0;
		}
	}

	public final int getDistance(Coordinate coor) {
		return (Math.abs(this.getLocationX() - coor.getLocationX()) + Math
				.abs(this.getLocationY() - coor.getLocationY()));
	}

	public final boolean isEqual(Coordinate coor) {
		if (this.getLocationX() == coor.getLocationX()) {
			if (this.getLocationY() == coor.getLocationY()) {
				return true;
			}
		}
		return false;
	}

	public final Coordinate findMidPoint(Coordinate coor) {
		return new Coordinate((getLocationX() + coor.getLocationX()) / 2,
				(getLocationY() + coor.getLocationY()) / 2);
	}
}
